

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-09-29
 * Time: 20:57
 */
class TreeNode{
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }

public class isSymmetric {
    public boolean isSame(TreeNode p,TreeNode q){
        if(p==null&&q!=null||p!=null&&q==null){
            return false;
        }
        if(p==null&&q==null){
            return true;
        }
        return (p.val==q.val&&isSame(p.left,q.right)&&isSame(p.right,q.left));
    }
    public boolean isSymmetric(TreeNode root) {
        return isSame(root.left,root.right);
    }
}
